import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
labels = ["第四周","第五周", "第六周",]
Forth_absence = [3, 2, 2, 2, 2, 1.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Fifth_absence = [3, 3, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]
Sixth_absence = [2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0.5]
x = np.arange(len(labels))
width = 0.3
average_absence1 = sum(Fifth_absence) / len(Fifth_absence)
average_absence2 = sum(Sixth_absence) / len(Sixth_absence)
average_absence3 = sum(Forth_absence) / len(Forth_absence)
fig, ax = plt.subplots(figsize=(10, 6))
bar1 = ax.bar(x - width / 2, [average_absence1, average_absence2, average_absence3], width, label='平均每人缺席数')
ax.set_xlabel('周数')
ax.set_ylabel('平均每人缺席数')
ax.set_title('平均缺席数分析')
ax.set_xticks(x)
ax.set_xticklabels(labels)
ax.legend()
plt.savefig(r"D:\pycharm\python study\图像保存.png")
